package hong.jun.pet_home.controller.Registration_login;

import hong.jun.basic.util.AjaxResult;

import hong.jun.pet_home.domain.user.User;
import hong.jun.pet_home.domain.ato.Userato;
import hong.jun.pet_home.service.user.IUserService;
import hong.jun.pet_home.service.user.IWXUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@Api(tags = "User_Login_Register_Controller", description = "User_Login_Register_Controller | 用户登录注册接口")
@RequestMapping("/USER")
public class User_Login_Register_Controller {

    @Autowired
    private IUserService userService;
    @Autowired
    private IWXUserService iwxUserService;

    /**
     * email验证码
     */
    @PostMapping("/Verification_code/email")
    public AjaxResult userVerifycodeemail(@RequestBody String email) {
        String email1 = email.split("\"")[3];
        return userService.userVerifycodeemail(email1);
    }

    /**
     * phone验证码
     */
    @PostMapping("/Verification_code/phone")
    public AjaxResult userVerifycodephone(@RequestBody String phone) {
        String phone1 = phone.split(":")[1];
        return userService.userVerifycodephone(phone);
    }

    /**
     * email注册
     */
    @PostMapping("/register/email")
    public AjaxResult UserRegisterEmail(@RequestBody Userato userato) {
        return userService.RegisterEmail(userato);
    }

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public AjaxResult UserRegisterEmail(@RequestBody User user) {
        return userService.Userlogin(user);
    }

    /**
     * 微信登录
     */
    @PostMapping("/wxLogin")
    public AjaxResult wxLogin(@RequestBody Map<String, String> params, HttpServletResponse response) {
        return iwxUserService.wxLogin(params, response);
    }

    /**
     * 微信绑定用户
     */
    @PostMapping("/wxbinder")
    public AjaxResult wxbinder(@RequestBody Map<String, String> params, HttpServletResponse response) {
        return iwxUserService.wxbinder(params, response);
    }
}
